<template>
    <div class="comp-recommend">
        <loading v-if="isLoading === true"></loading>
        <div class="re-container" v-if="isLoading === false">
            <div class="re-title">TA的其他{{assetCode}}售賣中廣告</div>
            <table class="re-table">
                <thead>
                <tr>
                    <th width="50%">交易價格</th>
                    <th width="50%">付款方式</th>
                </tr>
                </thead>
                <tbody class="tbody">
                <tr class="tr" v-for="item in list" v-if="isLoading === false && list && list.length > 0" @click="goDetail(item)" style="cursor: pointer;">
                    <td width="50%">{{item.tradePrice}}{{item.currency}}</td>
                    <td width="50%">{{item.payInfoText}}</td>
                </tr>
                </tbody>
            </table>
            <loading v-if="isLoading"></loading>
            <no-data v-if="isLoading === false && list && list.length === 0"></no-data>
        </div>
    </div>
</template>

<script type="text/babel">
    import lib from '../../../../common/lib';
    import commonUtil from '../../../../common/util';
    import Loading from '../../../../../grsc-base/component/Loading.vue';
    import NoData from '../../../../../grsc-base/component/NoData.vue';
    import service from '../service';

    const PAGE_SIZE = 5;

    export default {
        components: {
            Loading,
            NoData
        },
        data() {
            return {
                lib,
                commonUtil,
                isLoading: true,
                isRequesting: false,
                list: []
            };
        },
        watch: {

        },
        props: {
            adId: {
                type: Number,
                default: 0
            },
            assetCode: {
                type: String,
                default: 'ACT'  // ACT/BTC/USC
            }
        },
        created(){
            this.isLoading = true;
            service.advertOtherSellQuery({
                advertId: this.adId,
                assetCode: this.assetCode,
                pageNo: 1,
                pageSize: PAGE_SIZE
            }).done((rep) => {
                this.isLoading = false;
                if (rep.code === window.CODE.SUCCESS) {
                    let list = rep.data.list;
                    $.map(list, (item, index) => {
                        item.payInfoText = lib.getBanksByPayInfo(item.c2cPayType);
                    });
                    this.list = list;
                }
            }).always(() => {
                this.isLoading = false;
            });
        },
        methods: {
            goDetail(item) {
                window.open('/hk/c2c.html#/ad/detail/sell/' + item.advertId);
//                window.location.href = './c2c.html#/ad/detail/sell/' + item.advertId;
//                window.location.reload();
            }

        }
    }
</script>

<style lang="sass" rel="stylesheet/scss">

</style>